草庐IT

javascript - 在 ember 中访问 Controller 或 View 的实例

全部标签

ruby-on-rails - Ruby:我可以在类方法中使用实例方法吗?

我有一个包含此类方法的类:defself.get_event_record(row,participant)event=Event.where(:participant_id=>participant.id,:event_type_code=>row[:event_type],:event_start_date=>self.format_date(row[:event_start_date])).firstevent=Event.new(:participant_id=>participant.id,:event_type_code=>row[:event_type],:event_s

ruby-on-rails - 在 Controller 中找不到 namespace 内的 Ruby on Rails 模型

我是Rails的新手,无法弄清楚这个问题...我有一个ControllerAdmin::Blog::EntriesController在app/controllers/admin/blog/entries_controller.rb中定义我有一个模型叫做Blog::Entry定义在app/model/blog/entry.rb当我尝试从Controller访问我的模型时,我从这一行得到一个"uninitializedconstantAdmin::Blog::EntriesController::Blog":@blog_entries=Blog::Entry.find(:all)很明显,

ruby-on-rails - 我真的应该测试 Controller 吗?

我正在尝试获得最佳的代码覆盖率/开发时间结果目前我使用rspec+shoulda来测试我的模型,使用rspec+capybara来编写我的验收测试。我尝试为一个简单的crud编写一个Controller测试,但它花费的时间太长了,最后我得到了一个令人困惑的测试(可能是我的错)使用rspec进行Controller测试的最佳实践是什么?这是我的测试和我的Controller的要点(一个测试还没有通过):https://gist.github.com/991687https://gist.github.com/991685 最佳答案 也

ruby-on-rails - 如何在没有 CRUD 操作的情况下路由 Controller ?

我有一个包含许多操作的Controller:classTestsController当我像这样将它添加到我的routes.rb文件中时:resources:tests并执行rakeroutes任务我看到以下额外回合:testsGET/tests(.:format)tests#indexPOST/tests(.:format)tests#createnew_testGET/tests/new(.:format)tests#newedit_testGET/tests/:id/edit(.:format)tests#edittestGET/tests/:id(.:format)tests#s

ruby - 将实例方法委托(delegate)给类方法

在Ruby中,假设我有一个类Foo允许我对我的大量Foos进行分类。所有Foos都是绿色和球形的是自然界的基本法则,因此我定义了类方法如下:classFoodefself.colour"green"enddefself.is_spherical?trueendend这让我做Foo.colour#"green"但不是my_foo=Foo.newmy_foo.colour#Error!尽管my_foo显然是绿色的。显然,我可以定义一个调用self.class.colour的实例方法colour,但如果我有很多这样的基本特征,那将变得笨拙。我大概也可以通过定义method_missing来尝

ruby-on-rails - 直接通过 FTP 访问 Heroku?

我不想经历一个复杂的推送过程,每次我做一个小的改变都需要几分钟才能完成,我希望直接通过FTP访问我在Heroku服务器上的文件。这可能吗? 最佳答案 不,这是不可能的。虽然使用FTP直接推送更简单,但它是一种部署代码和管理应用程序的脆弱方式(难以跟踪所做的事情,难以重现或管理回滚等)。 关于ruby-on-rails-直接通过FTP访问Heroku?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/q

ruby - 如何在 rspec 之前访问元数据(:all)?

我希望能够在before(:all)方法期间显示测试组名称(和祖先):describe"Myawesomeapp"dobefore(:all)doputsrunning_example_group.metadata[:full_description]#这个想法是会产生输出:MyawesomeappMyawesomeappawesomewidget此数据在“it”子句中可用,但我无法在before(:all)中弄清楚。它不可用吗?我是不是犯了一个愚蠢的错误? 最佳答案 在before(:all)block中,没有“运行示例”,但您仍

ruby-on-rails - 最佳实践 - 在 Ruby on Rails View 中传递实例变量或使用参数?

根据下面的例子,最佳实践是什么?案例一controller.rb...defindex...@group=params[:group]@team=params[:team]@org=params[:org]...endindex.html.haml=link_to@group,'#'=link_to@team,'#'=link_to@org,'#'案例2controller.rb...defindex......endindex.html.haml=link_toparams[:group],'#'=link_toparams[:team],'#'=link_toparams[:org

ruby-on-rails - 无法覆盖设计密码 Controller

在我提交电子邮件以向我发送重置密码说明后,我需要我的Rails应用程序重定向到主页。设计,默认情况下在输入电子邮件后呈现登录表单。所以我试图覆盖Devise::PasswordsController并更改其redirect_to,但没有成功。事实上,我认为Rails甚至都没有上过我的课。这可能是一个非常愚蠢的错误,但我已经研究了半天,但没有成功。我的想法是覆盖here中的密码Controller.这是我的Controller:classPasswordsController路线.rb:devise_for:users,:controllers=>{:passwords=>"passwo

ruby-on-rails - 重命名 Rails 中的 Controller 并清除生成的内容

我一直在关注关于restful_authentication插件的railscast。他建议运行命令:脚本/生成经过身份验证的用户session我这样做了,一切都“很好”,但随后session将无法正常工作。再次检查该站点,他提到了一个命名标准并列出了更新的代码,其中声明:脚本/生成经过身份验证的用户sessionsession多元化。所以现在我有session_controller.rb,里面有一个SessionController,但我猜按照命名标准,它正在寻找SessionsController,导致代码失败并出现错误“NameErrorinSessionsController#